

cd "../replication-package"


/*    
	This Do-file cleans the CPS couple-level data, using the 'all women' file (allwomen_mis48_linked.dta).
   
	Including all women, but have a flag for women who are coupled in both months. 
   
*/ 



    *************************
	***** Data Cleaning *****
    *************************

*** Earnings do not have to by inflation-adjusted because we're using earnings share. '
//  But we need this for the earnings analyses 

*** CPI - adjust to 2019 US dolalrs 

import delimited "data/raw/cps_00087.csv", clear 
// data source: IPUMS CPS website 
// CPI is in 1999 USD
// Using CPI to be adjusted to 2019 USD
// cpi19: 2019=1 

// caution: if you're using CPS CPI99 variable, CPI99 was coded as a part of ASEC supplement
// so 2000 CPI99 is 1, instead of 1999
// make sure to match years

collapse (mean) cpi99, by(year)
gen realyear = year - 1 
rename year asecyear 
rename realyear year // because I used the ASEC data to download, need to subtract 1 from asecyear 
drop asecyear
order year cpi99
qui sum cpi99 if year==2019 
local cpi19 r(mean) 
gen cpi19 = cpi99/`cpi19'

set obs `=_N+1'
replace year = 2021 if year==.
sort year
replace cpi99 = cpi99[_n-1] if cpi99==.
replace cpi19 = cpi19[_n-1] if cpi19==.

preserve
rename year year4
keep if inrange(year4, 1982, 2020)
gen cpi19_mis4 = cpi19
keep year4 cpi19_mis4
save "data/cpi_4.dta", replace 
restore 

rename year year8 
keep if inrange(year8, 1982, 2020) 
gen cpi19_mis8 = cpi19
keep year8 cpi19_mis8
save "data/cpi_8.dta", replace 

	
use "data/allwomen_mis48_linked.dta", clear

*-----------------------------------*
**#---------- 1. Link rates ----------*
*-----------------------------------*

** in universe 
tab year4
gen post_pandemic_flag = 0
replace post_pandemic_flag = 1 if year4==2019 & month4>=3 // if MIS4 is 2019 March and onward, MIS8 would include 2020 March ~ pandemic.
replace post_pandemic_flag = 1 if year4>=2020 
tab post_pandemic_flag 
tab year4 post_pandemic_flag 

drop if post_pandemic_flag==1


// 0. drop DC
tab statefip4
tab statefip4, nol
gen DC_dum = statefip4==11
tab DC_dum 
drop if DC_dum==1 

// starting from couples 
gen eligcouple4 = inlist(unionstatf4, 1, 2)
tab matched_sp4 eligcouple4 //--> use 'matched_sp4'

tab matched_sp4 if linkable_mis48==1
tab matched_sp4 if linkable_mis48==1 & inrange(year4, 1982, 1991)
tab matched_sp4 if linkable_mis48==1 & inrange(year4, 2011, 2020) 

gen linkedcouple48 = inlist(match_mis48, 4, 7) & matchf_mis48==3
tab linkedcouple48 if linkable_mis48==1 & matched_sp4==1
tab linkedcouple48 if linkable_mis48==1 & matched_sp4==1 & inrange(year4, 1982, 1991)
tab linkedcouple48 if linkable_mis48==1 & matched_sp4==1 & inrange(year4, 2011, 2020) 

* Table 1b: by marital (unionstatf4==1) vs. cohabiting (unionstatf4==2) status 
tab matched_sp4 if linkable_mis48 & unionstatf4==1
tab linkedcouple48 if linkable_mis48 & unionstatf4==1 & matched_sp4==1
tab linkedcouple48 if linkable_mis48 & unionstatf4==1 & matched_sp4==1 & inrange(year4, 1994, 2005)
tab linkedcouple48 if linkable_mis48 & unionstatf4==1 & matched_sp4==1 & inrange(year4, 2011, 2020)

tab matched_sp4 if linkable_mis48 & unionstatf4==2
tab linkedcouple48 if linkable_mis48 & unionstatf4==2 & matched_sp4==1
tab linkedcouple48 if linkable_mis48 & unionstatf4==2 & matched_sp4==1 & inrange(year4, 1994, 2005)
tab linkedcouple48 if linkable_mis48 & unionstatf4==2 & matched_sp4==1 & inrange(year4, 2011, 2020)


// 1. linkable through MIS4-MIS8. : Appendix Table A1, row 1
tab linkable_mis48 // 92.96%
keep if linkable_mis48==1

// 2. matched through MIS4-8 : Appendix Table A1, row 2
tab matchf_mis48 // 74.87%
keep if matchf_mis48==3


// 3. married or cohabiting at MIS4 
tab unionstatf4 // 51.48%
gen marriedf4 =  unionstatf4==1
label var marriedf4 "women married with diff-sex partner at MIS4"

gen marrcohabf4 = marriedf4==1 | cohabf4==1 
tab marrcohabf4, m // : Appendix Table A1, row 3


// 4. partner charateristics availalbe 
tab match_mis48 
tab match_mis48 if marrcohabf4==1 

// married only 
gen married48_sample = marriedf4==1 & inlist(match_mis48, 4, 7) // including 'repartnered' (0.09%)
replace married48_sample = . if inlist(match_mis48, 5, 6) // linked to same partner, but gender, age, or race mismatch (1.57%) 
tab married48_sample marriedf4, col // among married women at MIS4, 97.85% are matched 
	   
// married & cohabiting 
gen marrcohab48_sample = marrcohabf4==1 & inlist(match_mis48, 4, 7)
replace marrcohab48_sample = 0 if inlist(match_mis48, 5, 6)
tab marrcohab48_sample if marrcohabf4==1 
	//: ID & demographic matches for both partners MIS4-MIS8 
	// : Appendix Table A1, row 4
	
tab marrcohab48_sample marrcohabf4, col 
tab marrcohab48_sample if marrcohabf4==1, m

*** Note: marrcohab48_sample includes cohabiting (MIS4) -> married (MIS8), diff-sex couples 
tab match_mis48 cohabtomarr 
tab marrcohab48_sample cohabtomarr, row
tab unionstatf4 cohabtomarr if marrcohab48_sample==1 & match_mis48==7, row // among those who were cohabiting at MIS4, around 9% are married to the same partner at MIS8 
tab match_mis48 if marrcohab48_sample==1 // around 0.1% are repartnered between MIS4 and MIS8  

label var married48_sample "MARRIED (diff-sex partner) at MIS4 and MIS8"
label var marrcohab48_sample "Married/Cohab (diff-sex partner) at MIS4 and MIS8"

*------------------------------------------------*
**#---------- 2. Women's age restriction ----------*
***------------------------------------------------*
gen women_agesamp = inrange(agef4, 16, 45)		// restricting her age to 16~45 at MIS4
tab women_agesamp, m // 47.22
tab women_agesamp if marrcohab48_sample==1, m
keep if women_agesamp==1 // : Appendix Table A1, row 5


*------------------------------------------*
**#---------- 3. Childless at MIS4 ----------*
*------------------------------------------*
gen childless_mis4 = nchildf4==0 
tab childless_mis4 if marrcohab48_sample==1, m // : Appendix Table A1, row 6

// to get 'eligible' child's age at MIS8. use this variable later (for Appendix Table A1, row 8)
gen firstbirth = 0 if childless_mis4==1
replace firstbirth = 1 if childless_mis4==1 & eldchf8==0 
replace firstbirth = . if childless_mis4==1 & inrange(eldchf8, 1, 90)
gen fb_sample = firstbirth!=. 

// young children 
gen yngchild_mis4 = inrange(eldchf4, 0, 9) | nchildf4==0 // eligible sample 
replace yngchild_mis4 = 1 if fb_sample==1
replace yngchild_mis4 = . if inrange(eldchf8, 11, 90)

tab yngchild_mis4 firstbirth if marrcohab48_sample==1
tab eldchf8 yngchild_mis4
gen eldch_sample = yngchild_mis4==1 

tab fb_sample eldch_sample
tab fb_sample eldch_sample if marrcohab48_sample==1

// recode and relabel eldest child so that 0 stands for 'no child'
gen eldch_re4 = .
replace eldch_re4 = 0 if nchildf4==0 
replace eldch_re4 = eldchf4 + 1 if nchildf4!=0 & eldchf4<10 // so that 0 stands for "no child"; 1 would stand for "0 yrs old"; ... 
tab eldch_re4
label def chlb 0 "No Child" 1 "0 yrs old" 2 "1 yr old" 3 "2 yrs old" 4 "3 yrs old" 5 "4 yrs old" ///
                6 "5 yrs old" 7 "6 yrs old" 8 "7 yrs old" 9 "8 yrs old" 10 "9 yrs old" 11 "10 years old"
label val eldch_re4 chlb 

gen eldch_re8 = .
replace eldch_re8 = 0 if nchildf4==0 & nchildf8==0
replace eldch_re8 = eldchf8 + 1 if eldch_re4!=. & eldchf8<11 

// making sure that children age 1~2 years old in between 
// or children aged backwards. 
replace eldch_re8 = . if childless_mis4==1 & eldchf8>0
replace eldch_re8 = . if (eldch_re8 > eldch_re4+2)
replace eldch_re8 = . if eldch_re8 < eldch_re4 

// making sure that this is an extension of fb sample 
replace eldch_re8 = . if eldch_re4==0 & eldch_re8>1 

label val eldch_re8 chlb
tab eldch_re8

tab eldch_re8 firstbirth
tab eldch_re8 if eldch_sample==1
tab eldch_re8 if eldch_sample==1 & marrcohab48_sample==1

// eldest child categories 
label def chlb2 0 "No child" 1 "0~2 yrs old" 2 "3~5 yrs old" 3 "6~10 yrs old"
recode eldch_re4 (0=0 "No child") (1/3=1 "0~2 yrs old") (4/6=2 "3~5 yrs old") (7/11=3 "6~10 yrs old"), gen(eldchcat_re4)
recode eldch_re8 (0=0 "No child") (1/3=1 "0~2 yrs old") (4/6=2 "3~5 yrs old") (7/11=3 "6~10 yrs old"), gen(eldchcat_re8)

tab eldchcat_re4 
tab eldch_re4 

tab eldchcat_re4 eldchcat_re8

*------------------------------------------------*
**#---------- 4. Employment not missing -----------*
*------------------------------------------------*

// empstat3*==0 is NIU; empstat*==1 is armed forces. 
gen has_empinfo = 0
replace has_empinfo = 1 if empstat3f4!=0 & empstat3m4!=0 & empstat3f8!=0 & empstat3m8!=0 /// 
						   & empstatf4!=1 & empstatf8!=1 & empstatm4!=1 & empstatm8!=1 
						   
tab has_empinfo // 98.87% --> this applies to all women, because woemn without any partner simply have 'missing = .' of employment status 
tab has_empinfo if marrcohab48_sample==1 
tab has_empinfo if marrcohab48_sample==1 & childless_mis4==1


foreach mis in f4 f8 m4 m8 {
	gen empdum_`mis' = empstat3`mis'==1
}


*----------------------------------------------------------*
**#---------- 5. Generating earnings and her share ----------*
*----------------------------------------------------------*
// note that there are single or separated or same-sex couple women included here as well 
// pay attention to their earnings share 
// earnings share should be 'missing' at either or both time points for these women 

// replacing missing earnings values as zero. 
// earnweek82on* variables are "weekly earnings before deductions"

// First, adjusting for inflation, using the cpi99 given from ipums (https://cps.ipums.org/cps/cpi99.shtml)
merge m:1 year4 using "data/cpi_4.dta", gen(merge_mis4)
merge m:1 year8 using "data/cpi_8.dta", gen(merge_mis8)
drop if cpsid==.
sum cpi19*

// Her and His logged weekly earnings, CPI-adjusted
// Inflation should not matter too much, bc we are calculating earnings share 
// some missing values for earnings is due to unemp (empstat3*==2) or olf (empstat3*==3). 
// recode these to zero. 
// "True" missing earnings information is either 0 or 9999.99 among employed workers

gen cpi19f4 = cpi19_mis4
gen cpi19f8 = cpi19_mis8
gen cpi19m4 = cpi19_mis4
gen cpi19m8 = cpi19_mis8

foreach mis in f4 f8 m4 m8  {
	
	gen earnings_zero_`mis' = earnweek`mis'	
	replace earnings_zero_`mis' = 0 if earnweek`mis'==9999.99 & inlist(empstat3`mis', 0, 2, 3) // those who are not working are zero-earners
	replace earnings_zero_`mis' = . if earnweek`mis'==9999.99 & empstat3`mis'==1 // real missing 
	replace earnings_zero_`mis' = . if earnweek`mis'==0 & empstat3`mis'==1 // if employed but zero earnings, also real missing
	
	label var earnings_zero_`mis' "Earnings for `mis', NOT inflation-adjusted"
	
	// top-code adjustment 
	replace earnings_zero_`mis' = earnings_zero_`mis'*1.4 if inrange(year4, 1982, 1988) & earnings_zero_`mis'>=999 & earnings_zero_`mis'!=.
	replace earnings_zero_`mis' = earnings_zero_`mis'*1.4 if inrange(year4, 1989, 1997) & earnings_zero_`mis'>=1923 & earnings_zero_`mis'!=.
	replace earnings_zero_`mis' = earnings_zero_`mis'*1.4 if inrange(year4, 1998, 2019) & earnings_zero_`mis'>=2884.61 & earnings_zero_`mis'!=.

	// inflation adjustment
	gen earnings_`mis'_cpi19 = earnings_zero_`mis'*cpi19`mis' if earnings_zero_`mis'!=. 
	
	gen earnings_zeromiss_`mis' = earnings_`mis'_cpi19==. 
	label var earnings_zeromiss_`mis' "Earnings missing for `mis'"
}

tab1 earnings_zeromiss_* // mostly men have missing earnings 

sum earnings_zero_*
bys empstat3f4: sum earnings_f4_cpi19 

/// generating her share
gen her_share_mis4 = earnings_f4_cpi19 / (earnings_f4_cpi19 + earnings_m4_cpi19)
gen her_share_mis8 = earnings_f8_cpi19 / (earnings_f8_cpi19 + earnings_m8_cpi19)
gen her_share_nomiss = her_share_mis4!=. & her_share_mis8!=.


*----------------------------------*
**#---------- 6. Education ----------*
*----------------------------------*

// * for those who had 12 yrs of educ but no hs degree, gave them 11.5
// * for those who had 5+ yrs of college but no master's degree, gave them 16. 
// * for those who had some college but no degree, gave them 13.5 (in the new file, "2" was also some college)
// * these decisions were made so that it would be clearer to categorize later. 

foreach mis in f4 m4 {
	recode educ`mis' (2=13.5) (10=2.5) (11=1) (12=2) (13=3) (14=4) ///
					 (20=5.5) (21=5) (22=6) (30=7.5) (31=7) (32=8) (40=9) (50=10) (60=11) ///
				     (70/71=11.5) (72/73=12) (80=13) (81=13.5) (90/92=15) ///
				     (100=15) (110=15.5) (111/122=16) (123=18) (124/125=20), gen(edyrs_`mis')
					 
	recode edyrs_`mis' (0/11.5=1 "Less than HS") (12=2 "HS grad") (13/15.5=3 "Some college") (16/20=4 "BA or higher"), gen(edcat_`mis')
	recode edcat_`mis' (1/3=0 "No BA") (4=1 "Yes BA"), gen(badum_`mis')
}

sum edyrs_*	
tab1 edcat_*
tab1 badum_* 


*---------------------------------------*
**#---------- 7. Race/Ethnicity ----------*
*---------------------------------------*

tab racef4 
tab hispanf4
	
label def racelb 1 "NH White" 2 "NH Black" 3 "Hispanic" 4 "NH Other"

foreach mis in f4 m4 {
	gen nhwht`mis' = 0
	replace nhwht`mis' = 1 if race`mis'==100 & inlist(hispan`mis', 0, 901, 902) // 100=white; 0=not hispanic; 901/902 missing or dk
	label var nhwht`mis' "Non-Hispanic White dummy"
	
	gen nhblk`mis' = 0
	replace nhblk`mis' = 1 if race`mis'==200 & inlist(hispan`mis', 0, 901, 902) // 200=black; 0=not hispanic; 901/902 missing or dk
	label var nhblk`mis' "Non-Hispanic Black dummy"

    gen hispd`mis' = 0
	replace hispd`mis' = 1 if inrange(hispan`mis', 100, 612) // 100~500 = hispan. 
	label var hispd`mis' "Hispanic dummy"

	gen nhoth`mis' = 0
	replace nhoth`mis' = 1 if race`mis'>=300 & inlist(hispan`mis', 0, 901, 902) 
	label var nhoth`mis' "Non-Hispanic other race dummy"

	gen reth`mis' = 0
	replace reth`mis' = 1 if nhwht`mis'==1
	replace reth`mis' = 2 if nhblk`mis'==1
	replace reth`mis' = 3 if hispd`mis'==1
	replace reth`mis' = 4 if nhoth`mis'==1
	
	label val reth`mis' racelb

}

// checking 
tab1 reth*, m // only some missing values in MIS8. 

*** ----------------------------------- ***
**# ----- 8. Occupation and industry ----- #**
*** ----------------------------------- ***
foreach g in f4 m4 f8 m8 {
		
	gen ocat`g' = .
	replace ocat`g' = 0 if inlist(empstat3`g', 2, 3) // for unemployed/nilf, no occ 
	replace ocat`g' = 1 if inrange(occ1990`g', 3,200) // managerial and professional specialty
	replace ocat`g' = 2 if inrange(occ1990`g', 203, 391) // technical, sales,  and administrative support
	replace ocat`g' = 3 if inrange(occ1990`g', 405, 469) // service
	replace ocat`g' = 4 if inrange(occ1990`g', 473, 498) // farming, forestry, and fishing
	replace ocat`g' = 5 if inrange(occ1990`g', 503, 890) // operators,  fabricators, and laborers 
	
	cap label drop ocatlb
	label def ocatlb 0 "Not working" 1 "Managerial/Professional" 2 "Tech, Sales, & Admin support" 3 "Service" 4 "Farming, Forestry, & Fishing" 5 "Operators, Fabricators, & Laborers"
	label val ocat`g' ocatlb
	tab ocat`g'
	
	recode ocat`g' (0 = 0) (1 = 1) (2/5 = 0), gen(manaprof`g')
	
	}


***----------------------------------------------------*
**#---------- 9. State abbreviation & Decade ----------*
***----------------------------------------------------*

gen state_a = statefip4
label define state_a  1 "AL" 2 "AK" 5 "AR" 4 "AZ" 6 "CA" 8 "CO" 9 "CT" 10 "DE" ///
		11 "DC" 12 "FL" 13 "GA" 15 "HI" 16 "ID" 19 "IA" 17 "IL" 18 "IN" 20 "KS" 21 "KY" 22 "LA" ///
		25 "MA" 24 "MD" 23 "ME" 26 "MI" 27 "MN" 29 "MO" 28 "MS" 30 "MT" 37 "NC" 38 "ND" ///
		31 "NE" 33 "NH" 34 "NJ" 35 "NM" 32 "NV" 36 "NY" 39 "OH" 40 "OK" 41 "OR" 42 "PA" ///
		44 "RI" 45 "SC" 46 "SD" 47 "TN" 48 "TX" 49 "UT" 51 "VA" 50 "VT" 53 "WA" 55 "WI" ///
		54 "WV" 56 "WY", replace
label val state_a state_a		

recode year4 (1982/1989=1 "1980s") (1990/1999=2 "1990s") (2000/2009=3 "2000s") (2010/2020=4 "2010s"), gen(decade)

recode year4 (1982/1985=1 "1982-1985") (1986/1990=2 "1986-1990") (1991/1995=3 "1991-1995") (1996/2000=4 "1996-2000") ///
		     (2001/2005=5 "2001-2005") (2006/2010=6 "2006-2010") (2011/2015=7 "2011-2015") (2016/2020=8 "2016-2020"), gen(year4_cat)
			 
recode year8 (1982/1985=1 "1982-1985") (1986/1990=2 "1986-1990") (1991/1995=3 "1991-1995") (1996/2000=4 "1996-2000") ///
		     (2001/2005=5 "2001-2005") (2006/2010=6 "2006-2010") (2011/2015=7 "2011-2015") (2016/2020=8 "2016-2020"), gen(year8_cat)	
			 

* --------------------------------- *		 
* ----- 10. Assigning regions ----- *
* --------------------------------- *	
// check regions 
fre region
bys region: tab state_a

* ---------------------------- * 
* ----- 11. Final sample ----- *
* ---------------------------- * 

order cpsid cpsidpf cpsidpm4 cpsidpm8
local idlist cpsid* 
local keyvar statefip4 state_a region year4 year8 decade year*_cat childless_mis4 yngchild_mis4 eldchf4 eldch_re4 eldchf8 eldch_re8 eldchcat* firstbirth her_share_* earnings_*_cpi19 empdum_* manaprof*
local mediators reth* nhwht* nhblk* hispd* nhoth* edyrs* edcat* badum* age* marst* unionstatf4 schlcoll* cohab* edcat* 
local samplevar *_sample has_empinfo post_pandemic_flag
local weightvar wtfinlm4 wtfinlm8 wtfinlf8 wtfinlf4 hwtfinl4 hwtfinl8

keep `idlist' `keyvar' `mediators' `samplevar' `weightvar'

// first birth sample 
gen fb_sample_universe = marrcohab48_sample==1 & childless_mis4==1
gen lm_char_nomiss = her_share_nomiss==1 & has_empinfo==1 

tab lm_char_nomiss if fb_sample_universe==1 // Appendix Table A1, row 7
tab lm_char_nomiss if fb_sample_universe==1 & fb_sample==1 // Appendix Table A1, row 8, using the variable generated earlier 

gen fb_sample_marrcohab = fb_sample_universe==1 & lm_char_nomiss==1 & fb_sample==1
tab fb_sample_marrcohab 


// eldch sample 
gen eldch_universe = childless_mis4==1 | eldchf4<10 
replace eldch_universe = 0 if eldchf8>10 | eldchf8==.

gen eldch_sample_marrcohab = eldch_sample==1 & marrcohab48_sample==1 & lm_char_nomiss==1
replace eldch_sample_marrcohab = 0 if fb_sample_marrcohab==0 & eldch_re4==0
replace eldch_sample_marrcohab = 0 if eldch_re8==. 
tab eldch_sample_marrcohab
tab eldch_sample_marrcohab fb_sample_marrcohab
tab eldchcat_re4 eldchcat_re8 if eldch_sample_marrcohab==1 & fb_sample_marrcohab==0, m
tab eldchcat_re4 eldchcat_re8 if eldch_sample_marrcohab==1 & fb_sample_marrcohab==1, m

tab eldchcat_re4 eldch_sample_marrcohab, m

tab eldchcat_re4 eldchcat_re8 if eldch_sample_marrcohab==1, m


*---------------------------------------------------*
*---------- 11. Keeping the final samples ----------*
*---------------------------------------------------*
keep if fb_sample_marrcohab==1 | eldch_sample_marrcohab==1 
save "data/CPS_couple_wide.dta", replace 

*-------------------------------------------------------------------*
*---------- 12. Merging wiht state indicators + Long-form ----------*
*-------------------------------------------------------------------*
use "data/CPS_couple_wide.dta", clear 
merge m:1 year4 state_a using "data/state/state_level_context.dta"
tab _merge 
keep if _merge==3
drop _merge 

// mediators 
gen MIS4year = year4
gen MIS4year_cat = year4_cat 
gen MIS4_herre = rethf4
gen MIS4_herwht = nhwhtf4 
gen MIS4_hered = edcat_f4
gen MIS4_herba = badum_f4 
gen MIS4_herage = agef4 
gen MIS4_herMP = manaproff4 

// his mediators 
gen MIS4_hisre = rethm4
gen MIS4_hiswht = nhwhtm4 
gen MIS4_hised = edcat_m4 
gen MIS4_hisba = badum_m4 
gen MIS4_hisage = agem4 


foreach m in 4 8 {
	
	local n = `m'/4 
	
	rename year`m' year`n'
	rename year`m'_cat year_cat`n'
	
	rename her_share_mis`m' her_share`n'
	
	rename eldch_re`m' eldch_age`n'
	rename eldchcat_re`m' eldch_cat`n'
	
	rename earnings_f`m'_cpi19 her_earnings`n'
	rename earnings_m`m'_cpi19 his_earnings`n'
	
	rename hwtfinl`m' hwtfinl`n'
	rename wtfinlf`m' wtfinlf`n'
	rename wtfinlm`m' wtfinlm`n'
	
}

* Reshape 
reshape long year year_cat her_share eldch_age eldch_cat her_earnings his_earnings hwtfinl wtfinlf wtfinlm, i(cpsidpf) j(l_year) 

label var year_cat "5-year band of calendar year"
label var MIS4year_cat "5-year band of calendar year, at MIS4"

* Generating a flag for first birth. 
gen firstbir_flag = firstbirth
replace firstbir_flag = 0 if firstbirth==1 & l_year==1 // making sure that in the first survey year, no first child. 
rename firstbir_flag firstbir_fe // turning it "on" if first birth occurred in the second year.
tab firstbir_fe l_year 
tab firstbir_fe l_year if fb_sample_marrcohab==1, col

* Set up and save the dataset. 
xtset cpsidpf l_year 

save "data/CPS_state_FB_ELDCH_analytic.dta", replace 

  
  
/////////// /////////// /////////// /////////// FIN /////////// /////////// /////////// ///////////


